/**
 * 后台登录
 */

var message = {
	'-1' : '请输入用户名',
	'-2' : '请输入密码'
}
$(document).ready(function() {
var login = function() {
	var username = $('[name="username"]').val();
	var password = $('[name="password"]').val();
	
	if(!username) {
		$('[name="username"]').focus();
		$.message(message[-1]);
		return false;
	}
	if(!password) {
		$('[name="password"]').focus();
		$.message(message[-1]);
		return false;
	}
	var data = {username:$('[name="username"]').val(), password:$('[name="password"]').val()};
	var url = '/auth/login.json';
	$.post(url, data, function(dt) {
		if(dt.status) {
			$.message(dt.message);
		} else {
			var backurl = $('[name="backurl"]').val();
			if(backurl) window.location.href = backurl;
			else window.location.href="/";
		}
	}, 'json');
	return false;
}
$('[name="login-form"]').submit(login);
})